package com.tyut.controller;

import com.tyut.pojo.Manager;
import com.tyut.service.ManagerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 管理员控制器
 */
@Controller
public class ManagerController {
    @Resource
    private ManagerService managerService ;


    /**
     * 添加管理员
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/addManager")
    @ResponseBody
    public boolean addManager(HttpServletRequest request, HttpServletResponse response){

        Manager manager = new Manager();

        return managerService.addManager(manager);
    }
    //@RequestMapping(value = "addManager",produces = "application/json;charset=utf-8")

    /**
     * 删除管理员
     * @param manid
     */@RequestMapping(value = "/deleteManager/{manid}")
    public void deleteManager(@PathVariable("manid") Integer manid){
         managerService.deleteManager(manid);
    }

    /**
     * 修改管理员
     * @param manager
     */
    @RequestMapping("/updateManager")
    public void updateManager(Manager manager){
         managerService.updateManager(manager);
    }

    /**
     * 查询所有管理员
     * @return
     */
    @RequestMapping("/queryListManager")
    @ResponseBody
    public List<Manager> queryListManager(){
        List<Manager> managers = managerService.queryListManager();
        return managers;
    }

    /**
     * 根据id查询管理员
     * @param manid
     * @return
     */
    @RequestMapping("/queryManagerById/{manid}")
    @ResponseBody
    public Manager queryManagerById(@PathVariable("manid") Integer manid){
        Manager manager = managerService.queryManagerById(manid);
        return manager;
    }
    @RequestMapping("/loginManager")
    @ResponseBody
    public Manager loginManager(Manager manager){
        return managerService.loginManager(manager);
    }
}
